package com.example.demo.service;

import com.example.demo.datasources.DataSourceNames;
import com.example.demo.datasources.annotation.DataSource;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 测试多数据源
 */
@Service
public class DataSourceTestService {

    @Autowired
    private UserService userService;


    @DataSource(name = DataSourceNames.MASTER)
    public User queryUser(Long userId) {
        return userService.selectByKey(userId);
    }

    @DataSource(name = DataSourceNames.SLAVE)
    public User queryUser2(Long userId) {
        return userService.selectByKey(userId);
    }

    public User queryUser3(Long userId) {
        return userService.selectByKey(userId);
    }

}
